<template>
  <div>
    <!-- 待回运旧件查询 - 编辑页面 -->
    <BreakSpace label="索赔单信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel1" :list="formList" :cols="2" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <div style="padding-top: 3rem"></div>
    <BreakSpace label="旧件列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table1"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :datakey="'items'"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      height="auto"
      :isPagination="false"
      :isSelectColumn="false"
    >
    </FilterTable>
    <div style="padding-top: 3rem"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
<!--      <multiuse-button type="primary" @click="print">生成标签</multiuse-button>-->
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BasePrint ref="templateReturnList" :data="printList" template="templateWaitReturnLabel"/>
    <!-- //模板名templateWaitReturnLabel -->
    <img id="barcode" style="display: none" />
  </div>
</template>
<script>
import { getPartType } from '@/api/dictionary/index.js';
import { editSave, getReturnDetailByClaimId, generateLabel } from '@/api/usedPartsReturnManage/usedPartsReturn_DLR/usedPartsWaitReturnQuery';
import JsBarcode from 'jsbarcode';
import { dictionary } from '@/utils/dictMixin';

export default {
  mixins: [dictionary],
  props: ['rowData'],
  data() {
    return {
      dataList: [],
      huanxiajiandataList: [],
      fujiaxiangmudataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中服务站
      columns: this.creatHeader(),
      formList: this.createFormList(),
      saveData: null,
      printList: {
        rows: [],
      },
    };
  },
  created() {
    this.chuqi3();
    this.init(this.rowData);
  },
  methods: {
    async print() {
      // for (let i = 0; i < 52; i++) {
      //   // this.printList.rows.push({
      //   //   appId: 'beijing',
      //   //   warehouse: '株洲仓库',
      //   //   logo: 'https://bjev-cms-oss-public.oss-cn-beijing.aliyuncs.com/20210201/a878b02238524b8b9a533eac454af802.jpg',
      //   //   dealer: 'C0101',
      //   //   dealerName: '北京鹏元',
      //   //   model: 'C51EGUPJ3013',
      //   //   vin: 'ASDDJIYUELA1235749',
      //   //   purchaseDate: '2020-12-12',
      //   //   repairDate: '2021-02-02',
      //   //   mileage: 13794.0,
      //   //   claimNo: 'JS2102000172',
      //   //   partsNo: 'A00082412_IK07',
      //   //   number: 1,
      //   //   partsName: '前轮眉饰板总成-右',
      //   //   section: 20210201102744,
      //   //   explain: '车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.',
      //   //   factory: '株洲工厂',
      //   //   productionDate: '2018-12-28',
      //   //   codeUrl: '',
      //   //   barcode: 'null21720983',
      //   //   type: '正常索赔',
      //   //   changeNo: 'E00109661_IK08',
      //   //   change: '内后视镜底部护罩-右-亚',
      //   //   replaceNo: 'E00109661_IK08',
      //   //   replace: '内后视镜底部护罩-右-亚光黑色'
      //   // });
      //   this.printList.rows.push({
      //     appId: 'arcfox',
      //     warehouse: '株洲仓库',
      //     logo: require('@/assets/img/arcfox.png'),
      //     dealer: 'C0101',
      //     dealerName: '北京鹏元',
      //     model: 'C51EGUPJ3013',
      //     vin: 'ASDDJIYUELA1235749',
      //     purchaseDate: '2020-12-12',
      //     repairDate: '2021-02-02',
      //     mileage: 13794.0,
      //     claimNo: 'JS2102000172',
      //     partsNo: 'A00082412_IK07',
      //     number: 1,
      //     partsName: '前轮眉饰板总成-右',
      //     section: 20210201102744,
      //     explain: '车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.车辆前轮眉饰板开裂,无法卡住并贴前叶子板,更换前轮眉饰板总成件.',
      //     factory: '株洲工厂',
      //     productionDate: '2018-12-28',
      //     codeUrl: '',
      //     barcode: 'null21720983',
      //     type: '正常索赔',
      //     changeNo: 'E00109661_IK08',
      //     change: '内后视镜底部护罩-右-亚',
      //     replaceNo: 'E00109661_IK08',
      //     replace: '内后视镜底部护罩-右-亚光黑色'
      //   });
      // }
      console.log(this.rowData,1234567,this.rowData.claimId)
      let newVar = await generateLabel({claimId: this.rowData.claimId});
      this.printList.rows = newVar.data;
      this.printList.rows.map((x) => {
        if (x.appId == "beijing") {//判断logo
          x.logo = require('@/assets/img/beijing.png');
        } else {
          x.logo = require('@/assets/img/arcfox.png');
        }
      })
      this.printList.rows.map((x) => {//生成条形码
        JsBarcode('#barcode', x.codeUrl);
        this.$nextTick(function () {
          x.codeUrl = document.getElementById('barcode').src;
        });
      });
      this.$nextTick(() => {
        //调用打印组件
        this.$refs.templateReturnList.EXCUTE_PRINT();
      });
    },
    async init(val) {
      let newVar = await getReturnDetailByClaimId({ claimId: val.claimId });
      this.editData = newVar.data;
      console.log('=== 通过ID查询结果返回 ==== ', newVar, ' ======');
      this.formList.forEach((x) => {
        console.log(newVar);
        x.initialValue = newVar.data[x.fieldName];
      });
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(newVar.data.partList);
    },
    //索赔类型下拉框
    async chuqi3() {
      console.log('===== 获取下拉框数据 ====== ');
      const res = await getPartType({ type: 5510 });
      console.log('==========', res);
      if (res.resultCode == 200) {
        this.formList.find((x) => x.fieldName == 'cmsClaimType').initialValue = '';
        this.formList.find((x) => x.fieldName == 'cmsClaimType').itemList = res.data.map((y) => ({
          text: y.codeCnDesc,
          value: y.codeId,
        }));
      }
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.$refs.formPanel1.SUBMIT_FORM();
      if (this.saveData) {
        this.$emit('save', this.selectedRows);
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close');
    },
    chooseOrderNo() {
      this.visible = true;
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '服务中心代码',
          fieldName: 'ownerCode',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '服务中心名称',
          fieldName: 'dealerName',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '索赔类型',
          fieldName: 'cmsClaimTypeStr',
          // itemList: [],
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          placeholder: '请输入车型...',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'claimNo',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        { type: 'SELECT',
          label: '动力形式',
          fieldName: 'ifComm',
          placeholder: '请选择动力形式...',
          initialValue: '',
          readonly: true, // 只读
          disabled: true, //置灰
          itemList: this.createDictList('5543')
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '主损件代码',
          fieldName: 'partCode',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '主损件名称',
          fieldName: 'partName',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '采购渠道代码',
          fieldName: 'channelCode',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'DATE',
          label: '购车日期',
          fieldName: 'saleDate',
          valueFormat: 'yyyy-MM-dd',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'driveMile',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        // {
        //   type: 'INPUT',
        //   label: '旧件代码',
        //   fieldName: 'partCode',
        //   readonly: true // 只读
        // },
        // {
        //   type: 'INPUT',
        //   label: '旧件名称',
        //   fieldName: 'partName',
        //   readonly: true // 只读
        // },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'licenseNo',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '故障现象代码',
          fieldName: 'sysCode4',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '故障现象名称',
          fieldName: 'sysName4',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '故障原因代码',
          fieldName: 'frCode',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        {
          type: 'INPUT',
          label: '故障原因名称',
          fieldName: 'frName',
          readonly: true, // 只读
          disabled: true, //置灰
        },
        // {
        //   type: 'INPUT',
        //   label: '检查结果',
        //   fieldName: 'partStatus222',
        //   readonly: true // 只读
        // }
      ];
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true },
        { title: '维修单号', dataIndex: 'roNo', sorter: true },
        { title: '旧件id', dataIndex: 'partId', sorter: true, hidden: true },
        { title: '旧件代码', dataIndex: 'partCode', sorter: true },
        { title: '旧件名称', dataIndex: 'partName', sorter: true },
        { title: '回运数量', dataIndex: 'partCount', sorter: true, width: 100 },
        { title: 'VIN', dataIndex: 'vin', sorter: true, width: 150 },
        {
          title: '返件类型', dataIndex: 'returnType', sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.returnType, '5585')}</span>;
          }
        },
      ];
    },
  },
};
</script>
<style lang="less" scoped></style>
